package com.app;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;
import springfox.documentation.oas.annotations.EnableOpenApi;

import java.net.InetAddress;


@EnableOpenApi
@SpringBootApplication
@ServletComponentScan(basePackages ="com.app.conf.SqlInjectFilter")
@MapperScan(basePackages = {"com.app.mapper"})
@EnableScheduling
public class PatrolApplication {

	public static void main(String[] args) throws Exception {
//		ConfigurableApplicationContext context = SpringApplication.run(jtSmartCityApplication.class, args);
//		context.getBean(Server.class).start();
		ConfigurableApplicationContext application = SpringApplication.run(PatrolApplication.class, args);
		Environment env = application.getEnvironment();
		String ip = InetAddress.getLocalHost().getHostAddress();
		String port = env.getProperty("server.port");
		String path = env.getProperty("server.servlet.context-path");
		System.err.println("\n\t" +"External访问网址: \thttp://" + ip + ":" + port + path);
		System.err.println("\n\t" +"jtSmartCityApplication 项目启动成功！");
		System.err.println("\n\t" +"swagger3访问路径：http://"+ip+":"+port+path+"/doc.html#/home");

	}
	@Bean
	public RestTemplate restTemplate(RestTemplateBuilder builder) {
		RestTemplate restTemplate = builder.build();
		restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
		return restTemplate;
	}
}
